//
//  ViewController.swift
//  自定义刷新控件
//
//  Created by Summer on 2017/12/14.
//  Copyright © 2017年 Summer. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    lazy var refreshControl:CZRefreshControl = CZRefreshControl()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if #available(iOS 11.0, *) {
            tableView.contentInset = UIEdgeInsets()
        } else {
            tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0)
        }
        
        print("tableView.contentOffset----\(tableView.contentOffset)")
        
        tableView.addSubview(refreshControl)
        
        refreshControl.addTarget(self, action: #selector(loadData), for: .valueChanged)
        
        loadData()
    }
    
    @objc func loadData() {
        print("开始刷新")
        refreshControl.beginRefreshing()
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) {
            print("结束刷新")
            self.refreshControl.endRefreshing()
        }
    }
}

